using Contract.Infrastructure;
using Contract.Infrastructure.Extensions;
using MediatR;
using Microsoft.EntityFrameworkCore;
using PublicCommon;
using System.Reflection;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddJWT(builder);

builder.Services.AddMediatR(Assembly.GetExecutingAssembly());

builder.Services.AddDbContextService<EfCoreDbContext>(builder.Configuration.GetConnectionString("connectionString"), true);

builder.Services.AddService();

builder.Services.AddHttpClient();
builder.Services.AddScoped<Cross_services_Helper>();

builder.Services.AddControllers().AddNewtonsoftJson(options =>
options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver());

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(o =>
{
    string s = AppDomain.CurrentDomain.BaseDirectory + "Contract.WebApi.xml";
    o.IncludeXmlComments(s, true);
});

var app = builder.Build();

// Configure the HTTP request pipeline.
//if (app.Environment.IsDevelopment())
//{
    app.UseSwagger();
    app.UseSwaggerUI();
//}

app.UseStaticFiles();

app.UseCors(x => x.AllowAnyHeader().AllowAnyOrigin().AllowAnyMethod());

app.UseAuthentication();
app.UseAuthorization();

app.MapControllers();

app.Run();
